package com.qd.pay.util;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author sjk
 */
public class RandomCharData {
    private RandomCharData() {

    }

    public static String createRandomCharData(int length) {
        StringBuilder sb = new StringBuilder();
        Random rand = ThreadLocalRandom.current();
        Random randData = ThreadLocalRandom.current();
        int data;
        for (int i = 0; i < length; i++) {
            int index = rand.nextInt(3);
            //目的是随机选择生成数字，大小写字母
            switch (index) {
                case 0:
                    data = randData.nextInt(10);
                    sb.append(data);
                    break;
                case 1:
                    data = randData.nextInt(26) + 65;
                    sb.append((char) data);
                    break;
                case 2:
                    data = randData.nextInt(26) + 97;
                    sb.append((char) data);
                    break;
                default:
                    break;
            }
        }
        return sb.toString();
    }

    public static String createData(int length) {
        StringBuilder sb = new StringBuilder();
        Random rand = ThreadLocalRandom.current();
        for (int i = 0; i < length; i++) {
            sb.append(rand.nextInt(10));
        }
        return sb.toString();
    }
}
